package com.cgw.auth.service.impl;

import com.cgw.auth.mapper.AccountMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.database.annotation.NeedDecrypt;
import org.database.annotation.NeedEncrypt;
import org.gavin.core.conf.SafetyFactory;
import org.gavin.core.enums.SafetyType;
import com.cgw.auth.entity.Account;
import com.cgw.auth.service.AccountService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *  服务层实现。
 *
 * @author gavin
 * @since 2024-01-05T13:38:25.8493635
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    private final AccountMapper accountMapper;

    private final SafetyFactory safetyFactory;

    @Override
    @NeedDecrypt
    public List<Account> getAllList() {
        return accountMapper.selectAll();
    }

    @Override
    @NeedEncrypt
    @Transactional(rollbackFor = Exception.class)
    public void add(Account account) {
        accountMapper.insert(account);
    }

    @Override
    @NeedDecrypt
    public Account getDetails(Integer detailsId) {
        safetyFactory.getSafety(SafetyType.SM2);
        return accountMapper.selectDetails(detailsId);
    }
}
